﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Drawing;
using System.Windows.Forms;

namespace SOEN341_SCHEDULER_PHASE1
{
    [Serializable()]
    class TimeTableBlock : ISerializable
    {
        #region Member Variables

        CustomDateTime _cdt;
        string _subject;
        string _location;
        Color _blocColor;

        #endregion

        #region Constructors

        /// <summary>
        /// Serialization Constructor
        /// </summary>
        /// <param name="info"></param>
        /// <param name="ctxt"></param>
        public TimeTableBlock(SerializationInfo info, StreamingContext ctxt)
        {
            _cdt = (CustomDateTime)info.GetValue("cdt", typeof(CustomDateTime));
            _subject = (string)info.GetValue("subject", typeof(string));
            _location = (string)info.GetValue("location", typeof(string));
            _blocColor = (Color)info.GetValue("col", typeof(Color));
        }

        /// <summary>
        /// Serialization method
        /// </summary>
        /// <param name="info"></param>
        /// <param name="ctxt"></param>
        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("cdt", _cdt);
            info.AddValue("subject", _subject);
            info.AddValue("location", _location);
            info.AddValue("col", _blocColor);
        }

        /// <summary>
        /// Parameterized constructor
        /// </summary>
        /// <param name="cdt">CustomeDateTime object</param>
        /// <param name="location">Location of ttb</param>
        /// <param name="blocColor">Color of bloc on grid</param>
        public TimeTableBlock(CustomDateTime cdt,string location, Color blocColor)
        {
            _cdt = new CustomDateTime(cdt);
            //_subject = subject;
            _location = location;
            _blocColor = blocColor;
        }

        #endregion


        #region Accessors
        /// <summary>
        /// Get the bloc color
        /// </summary>
        /// <returns>Color of the bloc</returns>
        public Color GetBlocColor()
        {
            return _blocColor;
        }

        /// <summary>
        /// Get the custome date time object
        /// </summary>
        /// <returns>The CustomDateTime object</returns>
        public CustomDateTime GetCustomDateTime()
        {
            return new CustomDateTime(_cdt);
        }

        /// <summary>
        /// Get the subject
        /// </summary>
        /// <returns>The ttb subject</returns>
        public string GetSubject()
        {
            return _subject;
        }

        /// <summary>
        /// Get the location
        /// </summary>
        /// <returns>The ttb location</returns>
        public string GetLocation()
        {
            return _location;
        }
        #endregion

        #region Mutators

        /// <summary>
        /// Set the bloc color
        /// </summary>
        /// <param name="blocColor">Color to set</param>
        public void SetBlocColor(Color blocColor)
        {
            _blocColor = blocColor;
        }

        /// <summary>
        /// Set the subject
        /// </summary>
        /// <param name="subject">subject to set</param>
        public void SetSubject(string subject)
        {
            _subject = subject;
        }

        /// <summary>
        /// set the location
        /// </summary>
        /// <param name="location">location to set</param>
        public void SetLocation(string location)
        {
            _location = location;
        }

        #endregion

        /// <summary>
        /// To string method
        /// </summary>
        /// <returns>Ttb to string</returns>
        public override string ToString()
        {
            return ("Subject: " + _subject + "\n" +
                "Location: " + _location + "\n\n" +
                _cdt.GetDayOfWeek().ToString() + "\n" +
                _cdt.GetTimeInterval());
        }

        public override bool Equals(object obj)
        {
            TimeTableBlock toComp = (TimeTableBlock)obj;
            return _cdt.Equals(toComp.GetCustomDateTime());
        }

    }
}
